﻿using FireChat.Client.Model.Message;
using FireChat.Client.Session.Receiver;
using FireChat.Share.Web.Actions;
using FireChat.Share.Web.Model.Query.Message;
using FireChat.Share.Web.Package;
using Newtonsoft.Json;

namespace FireChat.Client.Session.Manager;


/// <summary>
/// 消息管理类
/// </summary>
public static class MessageManager
{
    /// <summary>
    /// 发送好友消息
    /// </summary>
    /// <param name="chain">消息链</param>
    /// <param name="username">目标用户名</param>
    public static async Task<IResponse> SendFriendMessageAsync(this ClientCore client, string username, MessageChain chain)
    {
        FriendMessageQuery data = new()
        {
            Username = username,
            Content = JsonConvert.SerializeObject(chain)
        };


        var resp = ServertActions.FriendMessage.CreatePackage(data);
        return await client.SendReceiveAsync(resp);
    }
}
